package com.adinnet.admin.content.service.impl;

import com.adinnet.admin.content.model.Content;
import com.adinnet.admin.content.mapper.ContentMapper;
import com.adinnet.admin.content.model.vo.AdvertisementReq;
import com.adinnet.admin.content.service.ContentService;
import com.adinnet.common.utils.StringUtil;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 素材表 服务实现类
 * </p>
 *
 * @author chenjia
 * @since 2020-12-14
 */
@Service
public class ContentServiceImpl extends ServiceImpl<ContentMapper, Content> implements ContentService {

    @Autowired
    private ContentMapper contentMapper;

    @Override
    public PageResult<Content> advertisementList(AdvertisementReq req) {
        Page<Content> iPage = new Page<>(req.getPage(), req.getLimit());
        QueryWrapper<Content> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("type",3,4).eq("deleted",0);
        if(!StringUtil.isBlank(req.getTitle())){
            queryWrapper.like("title",req.getTitle());
        }
        queryWrapper.orderByDesc("updated_date");
        IPage page = baseMapper.selectPage(iPage, queryWrapper);
        return new PageResult<Content>(page.getRecords(),page.getTotal());
    }

    @Override
    public JsonResult deleteIds(String adIds) {
        contentMapper.deleteIds(adIds);
        return JsonResult.ok("操作成功");
    }

    /**
     * @param type:
     * @Description: 查询关于公司/招聘信息/豆藤的养成 详情
     * @author zYshuai
     * @Date: 2020/12/17 16:58
     * @return: com.adinnet.core.JsonResult
     */
    @Override
    public JsonResult details(Integer type) {
        return JsonResult.ok().put("data", contentMapper.selectOne(new QueryWrapper<Content>().eq("deleted", 0).eq("type", type)));
    }

}

